#!/usr/bin/perl
# 
#  Exercise 6.10 
# 
# Write a subroutine that alters an array of lines in a file. Use pass by reference for 
# the array. Pass the subroutine a reference to the array, a regular expression, and a 
# string to replace the regular expression. All the lines of the array should be altered 
# by substituting the matches found for the regular expression by the replacement 
# string.
#
# Answer to Exercise 6.10

use strict;
use warnings;

# Let's read in this file for the array of lines:

my $file = 'exer06.10';

open ( EXER, $file) or die "Cannot open file $file\n";

my @file = <EXER>;

close EXER;

# Call the subroutine

alter_lines ( \@file, 'a.*t', 'BIOINFORMATICS');

print @file;

exit;

sub alter_lines {

	my($array_ref, $regexp, $replacement) = @_;

	# $array_ref is a reference to an array


	# Loop through the lines of the array, making the pattern substitution

	for (@$array_ref) {

		s/$regexp/$replacement/;
	}

	return 1;
}
